/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import dto.Student;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author NDH
 */
public class MyModel extends AbstractTableModel {

    public ArrayList<Student> listS;
    String[] columnNames = {"code", "name", "email"};

    public MyModel(ArrayList<Student> listS) {
        this.listS = listS;
    }

    @Override
    public int getRowCount() {
        return listS.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return listS.get(rowIndex).getCode();
            case 1:
                return listS.get(rowIndex).getName();
            case 2:
                return listS.get(rowIndex).getEmail();
            default:
                return null;
        }
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                listS.get(rowIndex).setCode(Integer.parseInt(aValue.toString()));
            case 1:
                listS.get(rowIndex).setName(aValue.toString());
            case 2:
                listS.get(rowIndex).setEmail(aValue.toString());

        }
    }
}
